package com.seckill.redis;

/**
 * redis前缀的公共抽象类
 *
 * @author yangjunwei
 * @date 2021/10/29 4:29 下午
 */
public abstract class BasePrefix implements KeyPrefix {

    /**
     * 失效时间
     */
    private final int expireSeconds;

    /**
     * key值前缀
     */
    private final String prefix;

    public BasePrefix(String prefix) {
        //0代表永不过期
        this(0, prefix);
    }

    public BasePrefix(int expireSeconds, String prefix) {
        this.expireSeconds = expireSeconds;
        this.prefix = prefix;
    }

    @Override
    public int expireSeconds() {
        //默认0代表永不过期
        return expireSeconds;
    }

    @Override
    public String getPrefix() {
        String className = getClass().getSimpleName();
        return className + ":" + prefix + ":";
    }


}
